package com.atguigu.study.ref;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @auther zzyy
 * @create 2024-12-04 20:58
 */
public class GenericDemo
{

    /*
    public Order getOrder(Order o) throws Exception
    {

    }


    public Object getObj(Object o) throws Exception
    {

    }
    */
    public <T> T getObject(Class<T> clazz) throws Exception
    {
        T t = clazz.newInstance();
        return t;
    }

    public static void main(String[] args)throws Exception
    {
        GenericDemo genericDemo = new GenericDemo();

        Product product = (Product) genericDemo.getObject(Class.forName("com.atguigu.study.ref.Product"));
        product.setId(11);
        product.setProductName("huawei Mate70");

        System.out.println(product);
    }
}







@AllArgsConstructor
@NoArgsConstructor
@Data
class Product
{
    private int id;
    private String productName;
}